package com.luoxiang.socialandroid.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.base.BaseActivity;
import com.luoxiang.socialandroid.utils.MmkvUtil;

public class RenameActivity extends BaseActivity {
    private ImageView icon_back;
    private EditText ed_rename;
    private TextView tx_editsize,bt_finish;

    @Override
    protected void initListener() {
        icon_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        ed_rename.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                tx_editsize.setText(String.valueOf(ed_rename.getText().length()));
            }
        });
        bt_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MmkvUtil.INSTANCE.encode("ed_rename", ed_rename.getText().toString().trim());
                RenameActivity.this.finish();
            }
        });
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        setContentView(R.layout.activity_rename);
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        icon_back = findViewById(R.id.icon_back);
        bt_finish = findViewById(R.id.bt_finish);
        ed_rename = findViewById(R.id.ed_rename);
        ed_rename.setText(name);
        tx_editsize = findViewById(R.id.tx_editsize);
        tx_editsize.setText(String.valueOf(name.length()));
    }
}
